// var i;
// var $item_Icon_UIBindings = require("./Item_Icon_UIBindings");
// var $resKeeper = require("./ResKeeper");
// var $bundleConfig = require("./BundleConfig");
// var $excel = require("./Excel");
// var $commonUtils = require("./CommonUtils");
// var $const_Hall = require("./Const_Hall");
// var $hallGlobalVariable = require("./HallGlobalVariable");
// var f = cc._decorator;
// var g = f.ccclass;
// var _ = f.property;
// var y = f.inspector;
// var m = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.init = function (e, t) {
//         var o = this;
//         this.auto_ui.txt_countLabel.string = "x" + t;
//         var n = 1;
//         switch (e) {
//             case $hallGlobalVariable.default.goldId:
//             case $hallGlobalVariable.default.diamondId:
//             case $hallGlobalVariable.default.powerId:
//                 var i = "goldIcon";
//                 if (e == $hallGlobalVariable.default.diamondId) {
//                     i = "diamondIcon";
//                 } else {
//                     if (e == $hallGlobalVariable.default.powerId) {
//                         i = "powerIcon";
//                     }
//                 }
//                 this._loadRes($bundleConfig.BundleNames.Common, "res/ui/tu/" + i, cc.SpriteFrame).then(function (e) {
//                     o.auto_ui.sp_icon.spriteFrame = e;
//                     $commonUtils.default.LimitSpriteMaxSize(o.auto_ui.sp_icon, $const_Hall.equipIconSize);
//                 });
//                 this._loadRes($bundleConfig.BundleNames.Common, "res/quality/quality_m_1", cc.SpriteFrame).then(
//                     function (e) {
//                         o.auto_ui.sp_quality.spriteFrame = e;
//                     }
//                 );
//                 break;
//             default:
//                 n = $excel.Excel.shuiguo(e).quality;
//                 this._loadRes(
//                     $bundleConfig.BundleNames.Common,
//                     "res/player/player" + (e - 1e3) + "_1",
//                     cc.SpriteFrame
//                 ).then(function (e) {
//                     o.auto_ui.sp_icon.spriteFrame = e;
//                     $commonUtils.default.LimitSpriteMaxSize(o.auto_ui.sp_icon, $const_Hall.equipIconSize);
//                 });
//                 this._loadRes($bundleConfig.BundleNames.Common, "res/quality/quality_" + n, cc.SpriteFrame).then(
//                     function (e) {
//                         o.auto_ui.sp_quality.spriteFrame = e;
//                     }
//                 );
//         }
//     };
//     __decorate([_($item_Icon_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     return __decorate([g], t);
// })($resKeeper.default);
// exports.default = m;


// import Item_Icon_UIBindings from "./Item_Icon_UIBindings";
// import ResKeeper from "./ResKeeper";
// import { BundleNames } from "./BundleConfig";
// import { Excel } from "./Excel";
// import CommonUtils from "./CommonUtils";
// import { equipIconSize } from "./Const_Hall";
// import HallGlobalVariable  from "./HallGlobalVariable";

// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * 建议类名：ItemIcon
//  */
// @ccclass
// class ItemIcon extends ResKeeper {
//     @property(Item_Icon_UIBindings)
//     public auto_ui: Item_Icon_UIBindings | null = null;

//     /**
//      * 初始化方法
//      * @param itemId 物品ID
//      * @param count 物品数量
//      * 建议方法名：initialize
//      */
//     public init(itemId: number, count: number): void {
//         this.auto_ui!.txt_countLabel.string = "x" + count;
//         let quality = 1;
//         switch (itemId) {
//             case HallGlobalVariable.goldId:
//             case HallGlobalVariable.diamondId:
//             case HallGlobalVariable.powerId:
//                 let iconName = "goldIcon";
//                 if (itemId === HallGlobalVariable.diamondId) {
//                     iconName = "diamondIcon";
//                 } else if (itemId === HallGlobalVariable.powerId) {
//                     iconName = "powerIcon";
//                 }
//                 this._loadRes(BundleNames.Common, `res/ui/tu/${iconName}`, cc.SpriteFrame).then((spriteFrame) => {
//                     this.auto_ui!.sp_icon.spriteFrame = spriteFrame as cc.SpriteFrame;
//                     CommonUtils.LimitSpriteMaxSize(this.auto_ui!.sp_icon, equipIconSize);
//                 });
//                 this._loadRes(BundleNames.Common, "res/quality/quality_m_1", cc.SpriteFrame).then((spriteFrame) => {
//                     this.auto_ui!.sp_quality.spriteFrame = spriteFrame as cc.SpriteFrame;
//                 });
//                 break;
//             default:
//                 quality = Excel.shuiguo(itemId).quality;
//                 this._loadRes(BundleNames.Common, `res/player/player${itemId - 1000}_1`, cc.SpriteFrame).then((spriteFrame) => {
//                     this.auto_ui!.sp_icon.spriteFrame = spriteFrame as cc.SpriteFrame;
//                     CommonUtils.LimitSpriteMaxSize(this.auto_ui!.sp_icon, equipIconSize);
//                 });
//                 this._loadRes(BundleNames.Common, `res/quality/quality_${quality}`, cc.SpriteFrame).then((spriteFrame) => {
//                     this.auto_ui!.sp_quality.spriteFrame = spriteFrame as cc.SpriteFrame;
//                 });
//         }
//     }

//     /**
//      * 加载资源方法
//      * @param bundleName 包名
//      * @param resourcePath 资源路径
//      * @param type 资源类型
//      * @returns Promise<cc.Asset>
//      * 建议方法名：loadResource
//      */
//     protected _loadRes(bundleName: string, resourcePath: string, type: typeof cc.Asset): Promise<cc.Asset> {
//         return new Promise((resolve, reject) => {
//             cc.assetManager.loadBundle(bundleName, (err, bundle) => {
//                 if (err) {
//                     reject(err);
//                     return;
//                 }
//                 bundle.load(resourcePath, type, (err, asset) => {
//                     if (err) {
//                         reject(err);
//                         return;
//                     }
//                     resolve(asset);
//                 });
//             });
//         });
//     }
// }

// export default ItemIcon;

import ItemIconUIBindings from "./Item_Icon_UIBindings";
import ResKeeper from "./ResKeeper";
import { BundleNames } from "./BundleConfig";
import { Excel } from "./Excel";
import CommonUtils from "./CommonUtils";
import { equipIconSize } from "./Const_Hall";
import FruitDataManager from "./HallGlobalVariable";

const { ccclass, property } = cc._decorator;

/**
 * 建议类名：ItemIcon
 * 物品图标类，用于管理物品图标的显示和资源加载
 */
@ccclass
class ItemIcon extends ResKeeper {
    @property(ItemIconUIBindings)
    public auto_ui: ItemIconUIBindings | null = null;

    /**
     * 初始化方法
     * @param itemId 物品ID
     * @param count 物品数量
     * 建议方法名：initialize
     */
    public initialize(itemId: number, count: number): void {
        this.auto_ui!.txt_countLabel.string = "x" + count;
        let quality = 1;
        switch (itemId) {
            case FruitDataManager.goldId:
            case FruitDataManager.diamondId:
            case FruitDataManager.powerId:
                let iconName = "goldIcon";
                if (itemId === FruitDataManager.diamondId) {
                    iconName = "diamondIcon";
                } else if (itemId === FruitDataManager.powerId) {
                    iconName = "powerIcon";
                }
                this._loadRes(BundleNames.Common, `res/ui/tu/${iconName}`, cc.SpriteFrame).then((spriteFrame) => {
                    this.auto_ui!.sp_icon.spriteFrame = spriteFrame as cc.SpriteFrame;
                    CommonUtils.limitSpriteSize(this.auto_ui!.sp_icon, equipIconSize);
                });
                this._loadRes(BundleNames.Common, "res/quality/quality_m_1", cc.SpriteFrame).then((spriteFrame) => {
                    this.auto_ui!.sp_quality.spriteFrame = spriteFrame as cc.SpriteFrame;
                });
                break;
            default:
                quality = Excel.shuiguo(itemId).quality;
                this._loadRes(BundleNames.Common, `res/player/player${itemId - 1000}_1`, cc.SpriteFrame).then((spriteFrame) => {
                    this.auto_ui!.sp_icon.spriteFrame = spriteFrame as cc.SpriteFrame;
                    CommonUtils.limitSpriteSize(this.auto_ui!.sp_icon, equipIconSize);
                });
                this._loadRes(BundleNames.Common, `res/quality/quality_${quality}`, cc.SpriteFrame).then((spriteFrame) => {
                    this.auto_ui!.sp_quality.spriteFrame = spriteFrame as cc.SpriteFrame;
                });
        }
    }

    /**
     * 加载资源方法
     * @param bundleName 包名
     * @param resourcePath 资源路径
     * @param type 资源类型
     * 建议方法名：loadResource
     * @returns Promise<cc.Asset>
     */
    protected _loadRes(bundleName: string, resourcePath: string, type: typeof cc.Asset): Promise<cc.Asset> {
        return new Promise((resolve, reject) => {
            cc.assetManager.loadBundle(bundleName, (error, bundle) => {
                if (error) {
                    reject(error);
                    return;
                }
                bundle.load(resourcePath, type, (error, asset) => {
                    if (error) {
                        reject(error);
                        return;
                    }
                    resolve(asset);
                });
            });
        });
    }
}

export default ItemIcon;